var maxLength = 300;
var readmoreText = '[đọc thêm...]';

jQuery(function(){
	applyReadmore();
});

function applyReadmore() {
	jQuery("p[rel=readmore]").each(function(){
		$p = jQuery(this);
		var text = $p.html();
		if (!$p.next().hasClass("readmore")) {
			if(text.length > maxLength){
				var limitText = text.substring(0, maxLength);
				$p.html(limitText);
				jQuery("<p class='text readmore'><a href='#'>"+readmoreText+"</a></p>").insertAfter($p);
				bindReadmore($p);
			}
		}
	});
}

function bindReadmore($p){
	$p.siblings("p.readmore").children("a").click(function() {
		$holder = $p.parents("div.entryContentEditor");
		rel = $holder.attr("rel");
		if (rel.indexOf("ENTRY_DONE") > -1) {
			id = rel.substring(11);
			window.location.href = "/done/view/" + id;
		} else {
			id = rel.substring(6);
			window.location.href = "/entry/view/" + id;
		}
		
		return false;
	});
}
